package com.example.mqtt.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.example.mqtt.entity.QueueSequence;
import com.example.mqtt.mapper.QueueSequenceMapper;
import com.example.mqtt.model.HistoryVO;
import com.example.mqtt.model.YesterdayDataVO;
import com.example.mqtt.service.HistoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2025/5/5 14:59
 **/
@Service
@RequiredArgsConstructor
public class HistoryServiceImpl implements HistoryService {
    private final QueueSequenceMapper queueSequenceMapper;

    @Override
    public List<HistoryVO> getHistoryList() {
        List<QueueSequence> queueSequences = queueSequenceMapper.queryQueue();
        return queueSequences.stream().map(item -> BeanUtil.toBean(item, HistoryVO.class)).toList();
    }

    @Override
    public YesterdayDataVO getYesterdayData(String targetDate) {
        List<QueueSequence> queueSequences = queueSequenceMapper.queryQueue();
        List<QueueSequence> currentDateList = queueSequences.stream().filter(item -> item.getServiceDate().equals(targetDate)).toList();

        return YesterdayDataVO.builder()
                .yesterdayQueueCount(currentDateList.size())
                .totalQueueCount(queueSequences.size())
                .build();
    }
}
